<template>
    <Form
            :form-items="formItems"
            :loading="formLoading"
            :init-data-url="$baseURL.attend +  '/attend/overtimelegal/' + $route.params.id"
            :format-form="formatForm"
    ></Form>
</template>

<script>
    import Form from '../../../../common-util/src/components/page/Form.vue'
    export default {
        components:{
            Form
        },
        data(){
            return {
                formLoading: false,
                formItems:[
                    {
                        field: {
                            name: 'name'
                        },
                        element:{
                            label: '名称',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'isAllowOvertime'
                        },
                        element:{
                            type: 'switch',
                            label: '是否允许加班',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'isApprove'
                        },
                        element:{
                            type: 'switch',
                            label: '加班是否需要审批',
                            required: true,
                            show: (form) => {
                                return form.isAllowOvertime
                            }
                        }
                    },
                    {
                        field: {
                            name: 'isDeductRestTime'
                        },
                        element:{
                            type: 'switch',
                            label: '是否扣除休息时间',
                            required: true,
                            show: (form) => {
                                return form.isAllowOvertime
                            }
                        }
                    },
                    {
                        field: {
                            name: 'restTime'
                        },
                        element:{
                            type: 'inputNumber',
                            label: '休息时长分钟数',
                            required: (form) => {
                                return form.isDeductRestTime
                            },
                            show: (form) => {
                                return form.isDeductRestTime && form.isAllowOvertime
                            }
                        }
                    },
                    {
                        field: {
                            name: 'atLeast'
                        },
                        element:{
                            type: 'inputNumber',
                            label: '最少加班（分）'
                        }
                    },
                    {
                        field: {
                            name: 'atMost'
                        },
                        element:{
                            type: 'inputNumber',
                            label: '最多加班（分）'
                        }
                    },
                    {
                        field: {
                            name: 'step'
                        },
                        element:{
                            type: 'inputNumber',
                            label: '加班步长'
                        }
                    },
                    {
                        field: {
                            name: 'remark'
                        },
                        element:{
                            label: '备注'
                        }
                    },
                    {
                        field: {
                            name: 'version'
                        }
                    },
                    {
                        element:{
                            type: 'button',
                            button:[
                                {
                                    action: 'submit',
                                    requestMethod:'put',
                                    url: this.$baseURL.attend +  '/attend/overtimelegal/' +this.$route.params.id,
                                    label: '保存'
                                },
                                {
                                    action: 'reset',
                                    label: '重置',
                                    type: 'default'
                                }
                            ]
                        }
                    }
                ]
            }
        },
        mounted(){
        },
        methods:{
            formatForm(form){
                if(!form.isAllowOvertime){
                    form.isDeductRestTime = null
                }
                return form
            }
        }
    }
</script>

<style scoped>

</style>